/*
 * Debug.java,v 1.0 2001/6/22 02:33:59 Copyright 2000 Precom, Inc. All rights reserved. Copyright 2000 Precom, Inc. Tous
 * droits reserved. Writer by Lee S Updated by Ruan Hui Updated by zzg
 * 
 * 由于WSAD的本地JDK中含有log4j， 与现有的log4j.jar有冲突。只用在本地改为System.out, 系统部署后把log4j打开
 */

package com.ybfenpan.tracer;

/**
 * This class is just a helper class to make it handy to print out debug statements
 */
public final class Debug {

    /* 控制显示信息的参数 */
    protected static boolean debuggingOn = true;

    /**
     * 设置是否显示输出
    * @Title: setDebug
    * @param debug debug
    * @author: Qiyh 2014-10-12
    */
    public static void setDebug(boolean debug) {
        debuggingOn = debug;
    }

    /**
     * 获得是否显示输出
    * @Title: getDebug
    * @return boolean
    * @author: Qiyh 2014-10-12
    */
    public static boolean getDebug() {
        return debuggingOn;
    }

    /**
    * @Title: print
    * @param msg msg
    * @author: Qiyh 2014-10-12
    */
    public static void print(Object msg) {
        if (debuggingOn)
            System.out.print(msg);
    }

    /**
    * @Title: println
    * @param msg msg
    * @author: Qiyh 2014-10-12
    */
    public static void println(Object msg) {
        if (debuggingOn)
            System.out.println(msg);
    }

    /**
    * @Title: printErr
    * @param msg msg
    * @author: Qiyh 2014-10-12
    */
    public static void printErr(Object msg) {
        System.out.println(msg);
    }

    /**
    * @Title: print
    * @param e e
    * @param msg msg
    * @author: Qiyh 2014-10-12
    */
    public static void print(Exception e, Object msg) {
        print((Throwable) e, msg);
    }

    /**
    * @Title: printErr
    * @param e e
    * @param errMsg errMsg
    * @author: Qiyh 2014-10-12
    */
    public static void printErr(Exception e, Object errMsg) {
        printErr((Throwable) e, errMsg);
    }

    /**
    * @Title: print
    * @param e e
    * @author: Qiyh 2014-10-12
    */
    public static void print(Exception e) {
        print(e, null);
    }

    /**
    * @Title: printErr
    * @param e e
    * @author: Qiyh 2014-10-12
    */
    public static void printErr(Exception e) {
        printErr(e, null);
    }

    /**
    * @Title: print
    * @param t t
    * @param msg msg
    * @author: Qiyh 2014-10-12
    */
    public static void print(Throwable t, Object msg) {
        if (debuggingOn) {
            println("Received throwable with Message: " + t.getMessage());
            if (msg != null)
                System.out.print(msg);
            t.printStackTrace();
        }
    }

    /**
    * @Title: printErr
    * @param t t
    * @param errMsg errMsg
    * @author: Qiyh 2014-10-12
    */
    public static void printErr(Throwable t, Object errMsg) {
        if (errMsg != null)
            System.out.print(errMsg);
        t.printStackTrace();
    }

    /**
    * @Title: print
    * @param t t
    * @author: Qiyh 2014-10-12
    */
    public static void print(Throwable t) {
        print(t, null);
    }

    /**
    * @Title: printErr
    * @param t t
    * @author: Qiyh 2014-10-12
    */
    public static void printErr(Throwable t) {
        printErr(t, null);
    }

    /**
    * @Title: 信息的输出，主要用于接口的入口和出口
    * @param message message
    * @author: Qiyh 2014-10-12
    */
    public static void info(Object message) {
        if (debuggingOn)
            System.out.println("[INFO]:" + message);
    }

    /**
    * @Title: 调试语句方法
    * @param message message
    * @author: Qiyh 2014-10-12
    */
    public static void debug(Object message) {
        if (debuggingOn)
            System.out.println("[DEBUG]:" + message);
    }

    /**
    * @Title: w警告语句方法
    * @param message message
    * @author: Qiyh 2014-10-12
    */
    public static void warn(Object message) {
        System.out.println("[WARN]:" + message);
    }

    /**
    * @Title: 异常
    * @param message message
    * @author: Qiyh 2014-10-12
    */
    public static void error(Object message) {
        System.out.println("[Error]:" + message);
    }

}
